<?php

	include "kernel.php";
    include "adw_functions.php";

	$link = ConnectToBase ();

    //TRUNCATE ALL TABLES WITH CURRENT CHANGABLE STAT DATA
    mysql_query("truncate table activeusers");
    mysql_query("truncate table chat");
    mysql_query("truncate table killboard");
    mysql_query("truncate table mission");
    mysql_query("truncate table postponed");
    mysql_query("truncate table sessions");
    mysql_query("truncate table sorties");
    mysql_query("truncate table webchat");
    //mysql_query("truncate table war");
    //mysql_query("insert into war (id) values('1')");

    //TRUNCATE FINALPILOTS
    mysql_query("truncate table finalpilots");

    //FILL FINALPILOTS
    $pilots_r = mysql_query("select * from pilots where class='Human pilot' order by id");

    while ($pilot = mysql_fetch_assoc($pilots_r)) {
    	mysql_query("insert into finalpilots (pilotid,squadronid,callsign,army,regdate,rank_date)
        values ('".$pilot[id]."','".$pilot[squadronid]."','".$pilot[callsign]."','".$pilot[ArmyID]."','".time()."','".time()."')");
    }

    //MAKE NULL all values in SQUADRONS
    mysql_query("
    	update
        	squadrons
        set
		lineid=0,
		isactive=0,

			fuel=0,
            ammo=0,
            repair=0,
            addfuel=0,
            addammo=0,
            addrepair=0,
            dfuel=0,
            dammo=0,
            drepair=0,
            eAir=0,
            eBom=0,
            eSAir=0,
            eTank=0,
            eCar=0,
            eArt=0,
            eAaa=0,
            eWag=0,
            eShip=0,
            fAir=0,
            fSAir=0,
            fTank=0,
            fCar=0,
            fArt=0,
            fAaa=0,
            fWag=0,
            fShip=0,
            Wound=0,
            deaths=0,
            TKON=0,
            BAIL=0,
            CRASHED=0,
            CAPTURED=0,
            DIED=0,
            MIA=0,
		KICK=0,  
		DIEDISCO=0,
            sorties=0,
            allsorties=0,
            given1=0,
            given2=0,
            given3=0,
            given4=0,
            given5=0,
            given6=0,
            given7=0,
            given8=0,
            given9=0,
            given10=0,
            given11=0,
            given12=0,
            given13=0,
            given14=0,
            given15=0,
            given16=0,
            given17=0,
            given18=0,
            given19=0,
            given20=0,
            pot1=0,
        	pot2=0,
        	pot3=0,
        	pot4=0,
        	pot5=0,
        	pot6=0,
        	pot7=0,
        	pot8=0,
        	pot9=0,
        	pot10=0,
        	pot11=0,
        	pot12=0,
        	pot13=0,
        	pot14=0,
        	pot15=0,
        	pot16=0,
        	pot17=0,
        	pot18=0,
        	pot19=0,
        	pot20=0,
			rankpot=0,
			rgiven1=0,
			rgiven2=0,
		    rgiven3=0,
            rgiven4=0,
            rgiven5=0,
            rgiven6=0,
            rgiven7=0,
            rgiven8=0,
            rgiven9=0,
            rgiven10=0,
            squadpot=0,
            sgiven=0
            ");

    $r = mysql_query("select * from squadrons order by id");
    while ($res = mysql_fetch_assoc($r)) {

		$corank = GetCORank ($res[maxpilots]);
        $xorank = GetXORank ($res[maxpilots]);
        $rankpot = GetRankPot ($res[maxpilots]);

        $co_r = mysql_query("select pilotid from finalpilots where callsign='".$res[coname]."'");
        $co = mysql_fetch_assoc($co_r);
        $co = $co[pilotid];
        $xo_r = mysql_query("select pilotid from finalpilots where callsign='".$res[xoname]."'");
        $xo = mysql_fetch_assoc($xo_r);
        $xo = $xo[pilotid];

        mysql_query("update squadrons set rankpot='$rankpot',comander='".$co."',xcomader='".$xo."', regdate='2005-06-22' where id='".$res[id]."'");
echo "update squadrons set rankpot='$rankpot',comander='".$co."',xcomader='".$xo."', regdate='2005-06-22' where id='".$res[id]."'\r\n";
        mysql_query("update finalpilots set rank='$corank',rank_date='".time()."' where pilotid='".$co."'");
echo "update finalpilots set rank='$corank',rank_date='".time()."' where pilotid='".$co."'\r\n";
        mysql_query("update finalpilots set rank='$xorank',rank_date='".time()."' where pilotid='".$xo."'");
echo "update finalpilots set rank='$xorank',rank_date='".time()."' where pilotid='".$xo."'\r\n";

    }



?>